package work.parabola.keyboardswitch.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import work.parabola.keyboardswitch.common.ResponseCode;
import work.parabola.keyboardswitch.common.ServerResponse;
import work.parabola.keyboardswitch.common.UserConst;
import work.parabola.keyboardswitch.pojo.UserSession;
import work.parabola.keyboardswitch.pojo.query.plate.AddTesterQuery;
import work.parabola.keyboardswitch.pojo.query.plate.ListQuery;
import work.parabola.keyboardswitch.service.IPlateService;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/plate/")
public class PlateController {

    @Autowired
    private IPlateService iPlateService;

    @RequestMapping("addTest.do")
    public ServerResponse addTester(HttpSession session, @RequestBody AddTesterQuery addTesterQuery) {
        UserSession userSession = (UserSession) session.getAttribute(UserConst.CURRENT_USER);
        if (userSession == null) {
            return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), ResponseCode.NEED_LOGIN.getDesc());
        }
        return this.iPlateService.addTester(addTesterQuery, userSession);
    }



}
